<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    function to(promise, errExt) {
      return promise
        .then(data => [null, data])
        .catch(err => {
          if(errExt) {
            const parsedError = Object.assign({}, err, errExt)
            return [parsedError, null]
          }
          return [err, null]
        })
    }
    function fetchTest(data) {
      return new Promise((resolve) => {
        throw new Error('123')
        setTimeout(() => {
          resolve(data)
        }, 2000)
      })
    }
    async function test() {
      const [err, data] = await to(fetchTest([1,2,3]))
      if(!err) {
        console.log(data);
      } 
    }
    test()
  </script>
</body>
</html>